<template>
  <div>
    <!-- 新增修改表单 -->
    <el-dialog :title="textMap[dialogStatus]+'('+parentNodeName+')'" :visible.sync="DialogFormVisibleCom"
               append-to-body>
      <el-form ref="dataForm" :rules="rules" :model="formSubmitDataCom" label-position="right" label-width="100px"
               style="width: 90%; margin:10px auto;">

        <el-row :gutter="20">
          <el-col :span="12">
            <!-- 节点代码： -->
            <el-form-item label="节点代码：" prop="node_code">
              <el-input v-model="formSubmitDataCom.node_code" :disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 节点名称： -->
            <el-form-item label="节点名称：" prop="node_name">
              <el-input v-model="formSubmitDataCom.node_name"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <!-- 节点类型 -->
            <el-form-item label="节点类型" prop="node_type">
              <el-select 
              v-model="formSubmitDataCom.node_type" 
              class="filter-item" 
              placeholder="Please select"
              :disabled="dialogStatus==='create'"
              >
                <!-- <el-option v-for="item in lpOptions" :key="item.lp_code" :label="item.lp_name" :value="item.lp_code"/> -->
                <el-option
                  v-for="item in allNodeTypesOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled">
                </el-option>

              </el-select>
            </el-form-item>
          </el-col>

          <template v-if="this.formSubmitData.node_type === '2'">
          <el-col :span="12">
            <!-- 访问源编码 -->
            <el-form-item label="访问源编码" prop="acs_code">
              <el-input v-model="formSubmitDataCom.acs_code"/>
            </el-form-item>
          </el-col>


          <el-col :span="12">
            <!-- 路径+程序名 -->
            <el-form-item label="路径+程序名" prop="path_pg_name">
              <el-input v-model="formSubmitDataCom.path_pg_name"/>
            </el-form-item>
          </el-col>
          </template>
          <!-- <el-col :span="12">
            <el-radio
              v-model="formSubmitDataCom.status"
              label="1"
            >启用
            </el-radio>
            <el-radio
              v-model="formSubmitDataCom.status"
              label="0"
            >停用
            </el-radio>
          </el-col> -->


          <!-- 所属法人 -->
          <!-- <el-col :span="12">
            <el-form-item label="所属法人：" prop="lp_code">
              <el-input v-model="formSubmitDataCom.lp_code" />
            </el-form-item>
          </el-col> -->

        <el-col :span="24">
            <!-- 备注 -->
            <el-form-item label="备注：" prop="remark">
              <el-input type="textarea" v-model="formSubmitDataCom.remark" placeholder=""></el-input>
            </el-form-item>
          </el-col>

        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <!-- <el-button @click="DialogFormVisibleCom = false">
          取消
        </el-button> -->
        <el-button @click="resetFormData">
          重置
        </el-button>
        <el-button type="primary" @click="dialogStatusClick">
          提交
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// import PageHeaderLayout from '@/layouts/PageHeaderLayout'
// import ApeDrawer from '@/components/ApeDrawer'
// import { mapGetters } from 'vuex'

export default {
  name: 'submitForm',
  components: {
    //PageHeaderLayout,
  },
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false
    },
    dialogStatus: {
      type: String,
    },
    parentNodeName: {
      type: String,
    },
    // tableColumn: {
    //     type: Array,
    //     default() {
    //         return []
    //     }
    // },
    formSubmitData: {
      type: Object,
      default: function () {
        return {
          id: undefined,
          node_name: '',
          node_code: '',
          parent_node_name: '',
          node_type: '',
          acs_code: '',
          path_pg_name: '',
          remark: '',
          status: "1",
        }
      }
    },
    allNodeTypesOptions:{
      type: Array,
      default: function () {
        return []
      }
    }
  },
  // 定义属性
  data() {
    return {
      textMap: {
        update: '修改',
        create: '新增流程',
        addSonNode: '新增流程',
      },
      rules: {
         node_code: [{ required: true, message: '节点代码必填', trigger: 'change' }],
         node_name: [{ required: true, message: '节点名称必填', trigger: 'change' }],
        // currency: [{ required: true, message: '币种必填', trigger: 'change' }],
        // termplan: [{ required: true, message: '期限方案必填', trigger: 'change' }],
        // type: [{ required: true, message: 'type is required', trigger: 'change' }],
        // timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
        // title: [{ required: true, message: 'title is required', trigger: 'blur' }]
      },
      // 表单用到的值
      // calendarTypeOptions,
      // statusOptions: ['published', 'draft', 'deleted'],
    }
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {
    DialogFormVisibleCom: {
      get() {
        return this.dialogFormVisible
      },
      set(val) {
        this.$emit('update:dialogFormVisible', val)
      }
    },
    formSubmitDataCom: {
      get() {
        return this.formSubmitData
      },
      set(val) {
        this.$emit('update:formSubmitData', val)
      }
    },
  },
  // 监控data中的数据变化
  watch: {

  },
  // 方法集合
  methods: {
    // 重置
    resetFormData() {
       let exclude = []
      let replaceObj = {}
      if (this.dialogStatus === 'create') {
        exclude = [
          'coa_code',
        ]
        replaceObj = {
          lp_code: "123456", //曲线名称
        }
      }
      if (this.dialogStatus === 'update') {
        exclude = [
           'coa_code',
          
        ]
      }
      if (this.dialogStatus === 'addSonNode') {
        exclude = [
           'coa_code',
          
        ]
      }
      this.$emit('resetFormDataEmit', {
        exclude,
        replaceObj
      })
    },
    dialogStatusClick() {
      //  dialogStatus==='create'?createData():updateData()
      if (this.dialogStatus === 'create') {
        this.createData()
      } else if (this.dialogStatus === 'update') {
        this.updateData()
      } else {
        this.addSonNode()
      }
    },

    createData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$emit('handleFromCreateDataEmit')
          // this.temp.id = parseInt(Math.random() * 100) + 1024 // mock a id
          // this.temp.author = 'vue-element-admin'
          // createArticle(this.temp).then(() => {
          //   this.list.unshift(this.temp)
          //   this.dialogFormVisible = false
          //   this.$notify({
          //     title: 'Success',
          //     message: 'Created Successfully',
          //     type: 'success',
          //     duration: 2000
          //   })
          // })
        }
      })
    },

    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          // const tempData = Object.assign({}, this.formSubmitData)
          this.$emit('handleFromUpdateDataEmit')
        }
      })
    },
    addSonNode() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          // const tempData = Object.assign({}, this.formSubmitData)
          this.$emit('handleFromAddSonNodeEmit')
        }
      })
    }

  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {

  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

  },
  beforeCreate() {
  }, // 生命周期 - 创建之前
  beforeMount() {
  }, // 生命周期 - 挂载之前
  beforeUpdate() {
  }, // 生命周期 - 更新之前
  updated() {
  }, // 生命周期 - 更新之后
  beforeDestroy() {
  }, // 生命周期 - 销毁之前
  destroyed() {
  }, // 生命周期 - 销毁完成
  activated() {
  }, // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>

<style lang='scss' scoped>

</style>